/**
 * 
 */
package com.platform.common.utils;

import java.lang.reflect.Array;

/**
 * <pre>
 * 功能：数组操作通用类
 * </pre>
 * 
 * @author wei.gao
 */
public class ArrayUtils extends org.apache.commons.lang3.ArrayUtils {
	
	/**
	 * <pre>
	 * 功能：添加int到原有数组
	 * </pre>
	 * 
	 * @param oldArr
	 * @param item
	 * @param isFirst
	 * @return
	 */
	public static int[] append(int oldArr[], int item, boolean isFirst) {
		return append(oldArr, new int[] { item }, isFirst);
	}
	
	/**
	 * <pre>
	 * 功能：添加int数组到原有数组里面
	 * </pre>
	 * 
	 * @param oldArr
	 * @param newArr
	 * @param isFirst
	 * @return
	 */
	public static int[] append(int oldArr[], int newArr[], boolean isFirst) {
		if (oldArr == null) {
			return newArr;
		}
		if (newArr == null || newArr.length == 0) {
			return oldArr;
		}
		int ai2[] = new int[oldArr.length + newArr.length];
		if (!isFirst) {
			System.arraycopy(oldArr, 0, ai2, 0, oldArr.length);
			System.arraycopy(newArr, 0, ai2, oldArr.length, newArr.length);
		} else {
			System.arraycopy(newArr, 0, ai2, 0, newArr.length);
			System.arraycopy(oldArr, 0, ai2, newArr.length, oldArr.length);
		}
		return ai2;
	}
	
	/**
	 * <pre>
	 * 功能：添加long到原有数组
	 * </pre>
	 * 
	 * @param oldArr
	 * @param item
	 * @param isFirst
	 * @return
	 */
	public static long[] append(long oldArr[], long item, boolean isFirst) {
		return append(oldArr, new long[] { item }, isFirst);
	}
	
	/**
	 * <pre>
	 * 功能：添加long数组到原有数组
	 * </pre>
	 * 
	 * @param oldArr
	 * @param newArr
	 * @param isFirst
	 * @return
	 */
	public static long[] append(long oldArr[], long newArr[], boolean isFirst) {
		if (oldArr == null) {
			return newArr;
		}
		if (newArr == null || newArr.length == 0) {
			return oldArr;
		}
		long al2[] = new long[oldArr.length + newArr.length];
		if (!isFirst) {
			System.arraycopy(oldArr, 0, al2, 0, oldArr.length);
			System.arraycopy(newArr, 0, al2, oldArr.length, newArr.length);
		} else {
			System.arraycopy(newArr, 0, al2, 0, newArr.length);
			System.arraycopy(oldArr, 0, al2, newArr.length, oldArr.length);
		}
		return al2;
	}
	
	/**
	 * <pre>
	 * 功能：添加Object到原有数组
	 * </pre>
	 * 
	 * @param oldArr
	 * @param item
	 * @param isFirst
	 * @return
	 */
	public static Object[] append(Object oldArr[], Object item, boolean isFirst) {
		return append(oldArr, new Object[] { item }, isFirst);
	}
	
	/**
	 * <pre>
	 * 功能：添加Object数组到原有数组
	 * </pre>
	 * 
	 * @param oldArr
	 * @param newArr
	 * @param isFirst
	 * @return
	 */
	public static Object[] append(Object oldArr[], Object newArr[], boolean isFirst) {
		if (oldArr == null) {
			return newArr;
		}
		if (newArr == null) {
			return oldArr;
		}
		Object aobj2[] = (Object[]) Array.newInstance(((Object) (oldArr)).getClass().getComponentType(), oldArr.length + newArr.length);
		if (!isFirst) {
			System.arraycopy(((Object) (oldArr)), 0, ((Object) (aobj2)), 0, oldArr.length);
			System.arraycopy(((Object) (newArr)), 0, ((Object) (aobj2)), oldArr.length, newArr.length);
		} else {
			System.arraycopy(((Object) (newArr)), 0, ((Object) (aobj2)), 0, newArr.length);
			System.arraycopy(((Object) (oldArr)), 0, ((Object) (aobj2)), newArr.length, oldArr.length);
		}
		return aobj2;
	}
	
	/**
	 * <pre>
	 * 功能：int数组转Integer数组
	 * </pre>
	 * 
	 * @param ai
	 * @return
	 */
	public static Integer[] toObjectArray(int ai[]) {
		Integer ainteger[] = null;
		if (ai != null) {
			ainteger = new Integer[ai.length];
			for (int i = 0; i < ai.length; i++) {
				ainteger[i] = new Integer(ai[i]);
			}
		}
		return ainteger;
	}
	
	/**
	 * <pre>
	 * 功能：long数组转Long数组
	 * </pre>
	 * 
	 * @param ai
	 * @return
	 */
	public static Long[] toObjectArray(long ai[]) {
		Long aLong[] = null;
		if (ai != null) {
			aLong = new Long[ai.length];
			for (int i = 0; i < ai.length; i++) {
				aLong[i] = new Long(ai[i]);
			}
		}
		return aLong;
	}
	
}
